﻿using System;
namespace Netbits.Common.Conditions
{
	/// <summary>
	/// Null handling extensions for validator class
	/// </summary>
	public static partial class ValidatorExtensions
	{
		/// <summary>
		/// Check if the value is null. 
		/// </summary>
		/// <typeparam name="T">Type of value</typeparam>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <returns>Validator if the value is null, otherwise throws ConditionException</returns>
		public static Validator<T> IsNull<T>( this Validator<T> Validator_ )
		{
			if( Validator_.__Value != null )
				throw new ConditionException( "{0} should not be NULL", Validator_.GetArgumentName() );
			return Validator_;
		}

		/// <summary>
		/// Check if the value is null
		/// </summary>
		/// <typeparam name="T">Type of value</typeparam>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Message_">The message for the exception</param>
		/// <returns>The Validator if the value is null, otherwise throws ArgumentNullException</returns>
		public static Validator<T> IsNull<T>( this Validator<T> Validator_, string Message_ )
		{
			if( Validator_.__Value != null )
				throw new ConditionException( "{0}{1}{2} should not be NULL", Message_, Environment.NewLine, Validator_.GetArgumentName() );
			return Validator_;
		}

		/// <summary>
		/// Check if the value is NOT null
		/// </summary>
		/// <typeparam name="T">Type of value</typeparam>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <returns>Validator if the value is NOT null, otherwise throws ArgumentNullException</returns>
		public static Validator<T> IsNotNull<T>( this Validator<T> Validator_ )
		{
			if( Validator_.__Value == null )
				throw new ArgumentNullException( string.Format( "{0} should be NULL", Validator_.GetArgumentName() ) );
			return Validator_;
		}

		/// <summary>
		/// Check if the value is NOT null
		/// </summary>
		/// <typeparam name="T">Type of value</typeparam>
		/// <param name="Validator_">The strongly typed validator</param>
		/// <param name="Message_">The message for the exception</param>
		/// <returns>Validator if the value is NOT null, otherwise throws ArgumentNullException with the specified message</returns>
		public static Validator<T> IsNotNull<T>( this Validator<T> Validator_, string Message_ )
		{
			if( Validator_.__Value == null )
				throw new ArgumentNullException( string.Format( "{0}{1}{2} should be NULL", Message_, Environment.NewLine, Validator_.GetArgumentName() ) );
			return Validator_;
		}
	}
}
